package com.example.giftrecord.interceptor;

import com.example.giftrecord.controller.LoginController;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String authToken = request.getHeader("authToken");
        if (authToken == null || !LoginController.tokenSet.contains(authToken)) {
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
